#-*- coding: utf-8 -*-
'''
Created on Aug 24, 2012

@author: bbg
'''

from sqlalchemy import Integer, Column, String, MetaData, Table,DateTime
from sqlalchemy.orm import mapper

class Dish_report(object):
    '''
    菜品销售排名    
    '''
    
    _Mapper_ = None
    _company_id_ = -1    

    def __init__(self):
        self.unit_price =0
        self.unit =''
        self.stat_class_name =''
        self.dish_name =''
        self.modify_time ='1999-09-09'
        self.sold_count =0
        self.discount =0
        self.cook_extra_charge =0
        self.sold_charge =0
        self.uuid =''
        
    
    @staticmethod
    def doMapping(company_id):
        '''
        按company_id分库，每次生成对象前都要执行一次，以便map到正确的数据库上去
        '''
        if Dish_report._company_id_ == company_id:
            return
                
        if Dish_report._Mapper_ is not None:
            Dish_report._Mapper_.dispose()
            
        metaData = MetaData()
        dish_reportTable = Table('dish_report', metaData,
                           Column('unit_price', Integer, primary_key = True),
                           Column('unit', String, primary_key = True),
                           Column('stat_class_name', String, primary_key = True),
                           Column('dish_name', String, primary_key = True),
                           Column('uuid', String, primary_key = True),
                           Column('sold_count', Integer),
                           Column('discount', Integer),
                           Column('cook_extra_charge', Integer),
                           Column('sold_charge', Integer),
                           Column('modify_time', DateTime),                           
                           schema = "report_%s" % company_id)
                
        Dish_report._Mapper_ = mapper(Dish_report, dish_reportTable)
        
